using System;
using System.Windows.Forms;
using Client.UIHelper;
using ClientForms;

namespace SampleApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void BuyNowButton_Click(object sender, EventArgs e)
        {
            try
            {
                var buyMe = new BuyNowForm();
                buyMe.ShowDialog();
            }
            catch (DataStoreAppConfigException datStoreAppConfigException)
            {
                //Form cannot be used until the datstore has been initialized.
            }
        }

        private void RegisterButton_Click(object sender, EventArgs e)
        {
            try
            {
                var register = new RegisterForm();
                register.ShowDialog();
            }
            catch (DataStoreAppConfigException datStoreAppConfigException)
            {
                //Form cannot be used until the datstore has been initialized.
            }
        }

        private void SubmitFeedbackButton_Click(object sender, EventArgs e)
        {
            try
            {
                var feedback = new FeedbackForm();
                feedback.ShowDialog();
            }
            catch (DataStoreAppConfigException datStoreAppConfigException)
            {
                //Form cannot be used until the datstore has been initialized.
            }
        }

        private void ErrorReportButton_Click(object sender, EventArgs e)
        {
            string exceptionNullTest = null;
            try
            {
                //try and check the length without initializing the string to throw
                //an exception for testing
                if (exceptionNullTest.Length > 0)
                {
                }
            }
                //catch the exception to display the exception form
            catch (Exception ex)
            {
                try
                {
                    var exForm = new ExceptionForm(ex.Message, ex.Source, ex.StackTrace, "simulateExceptionButton_Click");
                    exForm.ShowDialog(this);
                }
                catch (DataStoreAppConfigException datStoreAppConfigException)
                {
                    //Form cannot be used until the datstore has been initialized.
                }
            }
        }

        private void VerifyLicensingButton_Click(object sender, EventArgs e)
        {
            var ds = new DataStore(this);
            string displayText;

            displayText = "Product State: " + ds.GetProductState + "\r\n\r\n\r\n";
            displayText += "Product License Level: " + ds.GetLicenseLevel.LicenseLevel + " " + ds.GetLicenseLevel.LicenseLevelID + "\r\n\r\n\r\n";
            displayText += "Is User Registered: " + ds.UserRegistered + "\r\n\r\n\r\n";
            try
            {
                displayText += "Trial Days Elapsed: " + ds.DaysElapsedSinceInstall + "\r\n\r\n\r\n";
            }
            catch (DataStoreChronologyException ex)
            {
                displayText += ex.Message;
            }
            MessageBox.Show(this, displayText);
        }
    }
}